<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="<c:url value="/js/plug/area/load_area.js" />"></script>
<style>
.detailTable input[type="text"]{
	width: 210px;
}
</style>
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
    <div data-options="region:'center',title:'',split:true" style="height:100%;">
		<form id="providerInfoForm" method="post" >
			<table class="detailTable"> 
    	 	<tr>
                <th>供应商名称:</th> 
                <td><input class="easyui-validatebox " id="chsName" name="chsName" data-options="required:true,validType:'chinese'"></td>
                <th>供应商编号:</th>
                <td><input class="easyui-validatebox " id="providerCode" name="providerCode" data-options="required:true">
                <input type="hidden" id="providerId" name="providerId" data-options="required:true">
                </td>
            </tr>
            <tr>
                <th>英文名:</th>
                <td><input class="easyui-validatebox " id="engName" name="engName" data-options="validType:'english'"></td>
                <th>拼音:</th><td><input class="easyui-validatebox" id="spell"name="spell" data-options="validType:'english'"></td>
            </tr>
             <tr>
                <th>地区:</th>
                <td>
                 <div id="loc" >
                   <select name="province" id="province" style="width:100px;">
                     <option value="0">选择省</option>
                   </select>   
                   <select name="city" id="city" style="width:100px;">
                     <option value="0">选择市</option>
                   </select>   
                   <select name="district" id="district" style="width:100px;">
                     <option value="0">选择地区</option>
                   </select>
                   <select name="street" id="street" style="width:100px;">
                     <option value="0">选择街道</option>
                   </select>
                  </div>
                  <input type="hidden" id="areaCode" name="areaCode" data-options="required:true" >
                  <input type="hidden" id="areaName" name="areaName" data-options="required:true" >
                <th>邮编:</th>
                <td><input class="easyui-validatebox" id="zip" name="zip" data-options="validType:'zip'"></td>
            </tr>
            <tr>
                <th>供应商地址:</th>
                <td colspan="3" ><input class="easyui-validatebox" id="address" name="address"  style="width:400px;" ></td>
            </tr>
            <tr>
                <th>电话:</th>
                <td><input class="easyui-validatebox " id="phone" name="phone" data-options="validType:'phone'"></td>
                <th>手机:</th>
                <td><input class="easyui-validatebox " id="mobile" name="mobile" data-options="validType:'mobile'"></td>
            </tr>
            <tr>
                <th>委托人:</th>
                <td><input class="easyui-validatebox " id="consigner" name="consigner"></td>
                <th>领导人:</th>
                <td><input class="easyui-validatebox " id="leaderName" name="leaderName"></td>
            </tr>
            <tr>
                <th>药品经营许可证:</th>
                <td><input class="easyui-validatebox " id="licenseNumber" name="licenseNumber"></td>
                <th>生产经营范围:</th>
                <td><input class="easyui-validatebox " id="productionScope" name="productionScope"></td>
            </tr>
            <tr>
                <th>营业执照号码:</th>
                <td><input class="easyui-validatebox " id="businessLicense" name="businessLicense"></td>
                <th>GSP号码:</th>
                <td><input class="easyui-validatebox " id="gspAttestation" name="gspAttestation"></td> 
            </tr>
            <tr>
                <th>开始查询日期:</th>
                <td><input class="easyui-datebox" id="searchStartDate" name="searchStartDate" ></td>
                <th>GMP号码:</th>
                <td><input class="easyui-validatebox " id="gmpAttestation" name="gmpAttestation"></td> 
            </tr> 
            <tr>
                <th>会员等级:</th>
                <td>
                    <input type="radio" id="levelId" name="levelId" value="1" checked="checked">普通会员
					<input type="radio" id="levelId" name="levelId" value="2" >高级会员
               </td>
               <th>是否审核:</th>
                <td>
                    <input type="radio" id="approveStatus" name="approveStatus" value="0" checked="checked">未审
					<input type="radio" id="approveStatus" name="approveStatus" value="1" >审核
               </td>
             </tr>
              
             
             
            <tr>
                <th>认证范围:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="attestationScope" name="attestationScope" style="width:400px;"></td>
            </tr>
            
            <tr>
                <th>引进原因:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="reason" name="reason" style="width:400px;"></td>
            </tr>            
            <tr>
                <th>注册地址:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="registerAddress" name="registerAddress" style="width:400px;"></td>
            </tr>
            <tr>
                <th>工厂地址:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="factoryAddress" name="factoryAddress" style="width:400px;"></td>
            </tr>
            <tr>
                <th>备注:</th>
                <td colspan="3" >
                   <textarea id="note" name="note" rows="2" cols="60"></textarea>
                </td>
            </tr>
			<tr>
			    <th>操作：</th>
				<td align="center" colspan="3" > 
					<input type="button" onclick="submitForm()" class="button" value="提交" >
					<input type="button" onclick="pms.resetForm('providerInfoForm')" class="button" value="重置" >
				 <!-- <input type="button" onclick="test()" class="button" value="测试" >      -->	   
				</td>
			</tr>
		</table>
		</form>
    </div>
</div>  
<script>

var flag =0; // 标示 0：save方法，1：update方法
$(function(){
	var providerId="<%=request.getParameter("code")%>";
	if(providerId=="null"){	//save	
		$("#loc").LocationSelect({
			data:"<c:url value='/js/plug/area/areas.json' />"
		});
	}else{					//update
		flag = 1;
		var param = {"providerId":providerId};
 		$.pmsAjax({
			url:'<c:url value="/emcprovider/showEmCProviderDetail.do"/>',
			data:param,
			success:function(data){
				var emCProvider = data.data.emCProvider;				
				if(data.code=="200"){
					//alertShow("成功");
					$('#providerInfoForm').form('load', emCProvider);
					//doemCProviderDetail(emCProvider);
					$("input[name='providerCode']").attr("readonly","readonly");
					$("#loc").LocationSelect({
						data:"<c:url value='/js/plug/area/areas.json' />",
						areaCode:emCProvider.areaCode
					});
				}else{
					alertError(data.result);
				}	
			}
		});
	}
})
function submitForm(){
	if(flag == 0){
		doInsert();
	}else{
		doUpdate();
	}	
}
//insert
function doInsert(){
	$('#providerInfoForm').form('submit', {
	    url:"/admin/emcprovider/insertProvider.do",  
	    onSubmit: function(param){
	    	if(!$("#providerInfoForm").form('validate')){
	    		return false;
	    	}
	    	var area = $("#loc").getLocation('all').code;
	    	var name = $("#loc").getLocation('all').name;
	    	$("#areaCode").val(area);
	    	$("#areaName").val(name);
	    	//alert(area);
	    	//console.log(area);
	    	//时间对比
	    }, 
	    success:function(data){
		    var ret = eval("("+data+")");
	     	if(ret.code=='200'){
	     		parent.alertShow("新增成功");
	     		parent.providersTable.refresh();
	     		parent.$("#w_provider_add").dialog('close');
		    }else{
		    	parent.alertError(ret.result);
			}
	    }
	});
}
//update
function doUpdate(){
	$('#providerInfoForm').form('submit', {
	    url:'<c:url value="/emcprovider/updateProvider.do"/>',
	    onSubmit: function(param){
	    	if(!$("#providerInfoForm").form('validate')){
	    		return false;
	    	}
	    	var area = $("#loc").getLocation('all').code;
	    	var name = $("#loc").getLocation('all').name;
	    	$("#areaCode").val(area);
	    	$("#areaName").val(name);
	    	//console.log(name);
	    	//时间对比
	    }, 
	    success:function(data){
		    var ret = eval("("+data+")");
	     	if(ret.code=='200'){
	     		parent.alertShow("修改成功");
	     		parent.providersTable.refresh();
	     		parent.$("#w_provider_add").dialog('close');
	     		
		    }else{
		    	alertError(ret.result);
			}
	    }
	});
}
function test(){
	$("#providerCode").val("1");
	$("#chsName").val("测试供应商");
	$("#engName").val("engName");
	$("#spell").val("spell");
	$("#address").val("天马路354号");
	$("#zip").val("324200");
	$("#phone").val("0570-88661035");
	$("#mobile").val("15300001111");
	
	$("#productionScope").val("testScope");
	$("#licenseNumber").val("ZA1100");
	$("#validStart").val("2011-12-14");
	$("#validEnd").val("2018-12-14");
	$("#businessLicense").val("11111111");
	$("#gspAttestation").val("22222222");
	$("#gmpAttestation").val("22222222");
	$("#attestationScope").val("attestationScope");
	$("#consigner").val("consigner");
	
	$("#reason").val("I don't know!");
	$("#note").val("新注册的供应商。。。");
	$("#registerAddress").val("湖墅南路123号");
	$("#leaderName").val("leaderName");
	$("#factoryAddress").val("环城北路1号");
	}
</script>
